package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.AfterIndentOrder;
import cn.stylefeng.guns.modular.system.mapper.AfterIndentOrderMapper;
import cn.stylefeng.guns.modular.system.model.params.AfterIndentOrderParam;
import cn.stylefeng.guns.modular.system.model.result.AfterIndentOrderResult;
import  cn.stylefeng.guns.modular.system.service.AfterIndentOrderService;
import cn.stylefeng.guns.sys.core.shiro.ShiroKit;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 售后单表 服务实现类
 * </p>
 *
 * @author 小飞
 * @since 2019-07-10
 */
@Service
public class AfterIndentOrderServiceImpl extends ServiceImpl<AfterIndentOrderMapper, AfterIndentOrder> implements AfterIndentOrderService {

    @Override
    public void add(AfterIndentOrderParam param){
        AfterIndentOrder entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(AfterIndentOrderParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(AfterIndentOrderParam param){
        AfterIndentOrder oldEntity = getOldEntity(param);
        AfterIndentOrder newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public AfterIndentOrderResult findBySpec(AfterIndentOrderParam param){
        return null;
    }

    @Override
    public List<AfterIndentOrderResult> findListBySpec(AfterIndentOrderParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(AfterIndentOrderParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param, ShiroKit.getUserNotNull().getId());
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(AfterIndentOrderParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private AfterIndentOrder getOldEntity(AfterIndentOrderParam param) {
        return this.getById(getKey(param));
    }

    private AfterIndentOrder getEntity(AfterIndentOrderParam param) {
        AfterIndentOrder entity = new AfterIndentOrder();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
